package com.example.app2;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Activity_rateSet extends AppCompatActivity {
    EditText et1,et2,et3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rateset);
        et1 = findViewById(R.id.editTextTextPersonName7);
        et2 = findViewById(R.id.editTextTextPersonName8);
        et3 = findViewById(R.id.editTextTextPersonName);

        Intent intent = getIntent();         //获取上一个界面传过来的intent
        Float dollar2 = intent.getFloatExtra("dollar",0.0f);
        Float eu2 = intent.getFloatExtra("eu",0.0f);
        Float jp2 = intent.getFloatExtra("jp",0.0f);

        et1.setText(String.valueOf(dollar2));
        et2.setText(String.valueOf(eu2));
        et3.setText(String.valueOf(jp2));

    }

    public void save(View v){
        Float dollarRate = Float.parseFloat(et1.getText().toString());
        Float euRate = Float.parseFloat(et2.getText().toString());
        Float jpRate = Float.parseFloat(et3.getText().toString());

        SharedPreferences spf = getSharedPreferences("rate_save", Activity.MODE_PRIVATE);
        SharedPreferences.Editor edt = spf.edit();   //将修改的数据放入spf中
        edt.putFloat("dollar_rate",dollarRate);
        edt.putFloat("eu_rate",euRate);
        edt.putFloat("jp_rate",jpRate);
        edt.apply();

        Intent back = getIntent();                 //再次获取intent
        Bundle bundle = new Bundle();              //new一个捆绑包
        bundle.putFloat("new_dollar",dollarRate);  //将此界面获取的数据放入bundle
        bundle.putFloat("new_eu",euRate);
        bundle.putFloat("new_jp",jpRate);

        back.putExtras(bundle);                     //将bundle存放到intent中
        setResult(1,back);                //为intent设置resultCode
        finish();                                   //完成数据交互，结束此页面，返回创建intent的页面

    }
}